from xui.dm_window import DmWindow
from xui.win32_hand_biz import Win32HandBiz
from uibiz.jd_order_card import JdOrderCard
from uibiz.weixin_msg_util import WeixinMsgUtil
import wx
import keyboard
from threading import Thread


# from tkinter import messagebox

class Hello(object):
    def begin(this):
        dmWin = DmWindow("8848")
        this.hand = Win32HandBiz()
        panelMain = wx.Panel(dmWin.frame)
        # wx.StaticText(panelMain, label="账号", pos=(10, 15), size=(70, 32), style=wx.ALIGN_RIGHT)
        # wx.StaticText(panelMain, label="密码", pos=(10, 52), size=(70, 32), style=wx.ALIGN_RIGHT)
        # inpUid = wx.TextCtrl(panelMain, pos=(90, 10), size=(120, 32), style = wx.TE_MULTILINE)
        #inpPwd = wx.TextCtrl(panelMain, style=wx.TE_PASSWORD, pos=(90, 46), size=(120, 32))
        # btnOk = wx.Button(panelMain, label="确定进入", pos=(10, 100), size=(120, 32))
        # btnCancel = wx.Button(panelMain, label="取消", pos=(140, 100), size=(120, 32))
        # btnOk = wx.Button(panelMain, label="确定进入", pos=(10, 100), size=(120, 32))

        btnOk = wx.Button(panelMain, label="读取", pos=(10, 10), size=(120, 30))

        wx.StaticText(panelMain, label="日志", pos=(10, 45), size=(70, 20), style=wx.ALIGN_LEFT)
        this.inpLog = wx.TextCtrl(panelMain, pos=(10, 70), size=(400, 220), style = wx.TE_MULTILINE)

        
        btnOk.Bind(wx.EVT_BUTTON, this.onClickOk)
        # btnCancel.Bind(wx.EVT_BUTTON, this.onClickCancel)
        this.initKeyBoard()

        dmWin.toShowWindow()
    
    def onClickOk(this, v2):
        # this.inpLog.AppendText("hehe-ok\n")
        jd = JdOrderCard()
        jd.readText()

    def key_ctrl_1(this): #定义按键按下时触发的函数
        this.log("按下了: ALT+1")
        this.hwnd = this.hand.getHwndMouseCur()
        title= this.hand.getHwndExeName(this.hwnd)
        print(title)
        # result = messagebox.showinfo("提示框", "这是一个示例提示框。")
    def key_ctrl_2(this):
        this.log("按下了: ALT+2")
        # this.hand.setTopWindow(this.hwnd)
        handLs = this.hand.initAllHand('chrome.exe')
        logStr = ''
        for hand in handLs:
            logStr += f"{hand['exeName']}\t{hand['title']}\n"
            this.log(logStr)
            # print(hand)
    def initKeyBoard(this): # 监听键盘
        p = Thread(target=this.initKeyBoard_do)
        p.start()
    def initKeyBoard_do(this): # 监听键盘
        keyboard.add_hotkey('alt+1', this.key_ctrl_1)
        keyboard.add_hotkey('alt+2', this.key_ctrl_2)
        keyboard.wait()
    def log(this,str):
        this.inpLog.AppendText(str+"\n")


hello = Hello()
hello.begin()